package exam;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main1 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str = br.readLine();
        while (!str.equals("0")) {
            int num = Integer.parseInt(str);
            int result = compute(num);
            System.out.println(result);
            str = br.readLine();
        }
    }

    private static int compute(int num) {
        if (num == 1) {
            return 0;
        }
        if (num == 2) {
            return 1;
        }

        int result = num / 3;
        int left = num % 3 + result;
        return result + compute(left);
    }
}
